<?php
function object_array($array) {
    if(is_object($array)) {
        $array = (array)$array;
    } if(is_array($array)) {
        foreach($array as $key=>$value) {
            $array[$key] = object_array($value);
        }
    }
    return $array;
}
/*
 * 获取头像
 * 作者：XiaoPang
 * Email：38295446@qq.com
 */
function imgUrl($hash){
    $imgUrl=object_array(json_decode(file_get_contents("http://tools.mobile.kugou.com/api/v1/singer_header/get_by_hash?hash=".$hash."&size=200&format=jsonp")));
    if ($imgUrl['status']==1){
        return $imgUrl['url'];
    }else {
        return $imgUrl['error'];
    }
}
/*
 * 获取音乐列表
 * 作者：XiaoPang
 * Email：38295446@qq.com
 */
function ajaxList($keywords,$pagesize){
    $html=object_array(json_decode(file_get_contents("http://ioscdn.kugou.com/api/v3/search/song?keyword=".$keywords."&page=1&pagesize=".$pagesize."&showtype=10&plat=2&version=7910&tag=1&correct=1&privilege=1&sver=5&qq-pf-to=pcqq.c2c")));
    $dataList=$html['data']['info'];
    for ($i=0;$i<count($dataList);$i++){
        $dataList[$i]['src']=object_array(json_decode(file_get_contents("http://m.kugou.com/app/i/getSongInfo.php?cmd=playInfo&hash=".$dataList[$i]['hash'])));
        $dataList[$i]['lrc']=U('Home/Index/lyric')."?hash=".$dataList[$i]['hash']."&timelength=".$dataList[$i]['src']['timeLength'];
        $res[$i]['title']=$dataList[$i]['filename'];
        $res[$i]['singer']=$dataList[$i]['singername'];
        $res[$i]['cover']=imgUrl($dataList[$i]['hash']);
        $res[$i]['src']=$dataList[$i]['src']['url'];
        $res[$i]['lyric']=$dataList[$i]['lrc'];
    }   
    if (!empty($res)){
        return $res;
    }else {
        return 'null';
    }
}
?>